﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;

public partial class Admin_OrderByDate : System.Web.UI.Page
{
    ShopDataContext dc = new ShopDataContext();

    protected void Page_Load(object sender, EventArgs e)
    {
        var query = from o in dc.Orders
                           where o.oDate.Value.Day == DateTime.Now.Day
                           select new { o.oOrderCode, o.oUser, o.oDate, o.oTypePayment, o.oStatus };

        ListView1.DataSource = query;
        ListView1.DataBind();
    }

    protected void ListView1_ItemDataBound(object sender, ListViewItemEventArgs e)
    {
        if (e.Item.ItemType == ListViewItemType.DataItem)
        {
            Label lblStatus = e.Item.FindControl("oStatusLabel") as Label;
            Label lblTypePayment = e.Item.FindControl("oTypePaymentLabel") as Label;
            Label lblUser = e.Item.FindControl("oUserLabel") as Label;

            switch (lblStatus.Text)
            {
                case "0":
                    lblStatus.Text = "Pending";
                    break;
                case "1":
                    lblStatus.Text = "Completed";
                    break;
                case "2":
                    lblStatus.Text = "Cancel";
                    break;
            }
            switch (lblTypePayment.Text)
            {
                case "2":
                    lblTypePayment.Text = "Credit Card";
                    break;
                case "3":
                    lblTypePayment.Text = "Direct Payments";
                    break;
            }
            MembershipUser user = Membership.GetUser(Guid.Parse(lblUser.Text));
            lblUser.Text = user.UserName;
        }
    }
    protected void btnFilter_Click(object sender, EventArgs e)
    {
        var query = from o in dc.Orders
                           where o.oDate >= DateTime.Parse(txtFrom.Text)
                           where o.oDate <= DateTime.Parse(txtTo.Text)
                           select new { o.oOrderCode, o.oUser, o.oDate, o.oTypePayment, o.oStatus };

        ListView1.DataSource = query;
        ListView1.DataBind();
    }
}